package com.ucs.ui;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.ucs.domain.Category;

public class CategoryListAdaptor extends ArrayAdapter<Category>{
	private int textViewResourceId;
    private List<Category> categories;

    public CategoryListAdaptor(Context context, int textViewResourceId, List<Category> categories) {
            super(context, textViewResourceId, categories);
            this.categories = categories;
            this.textViewResourceId = textViewResourceId;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {   
    	if (convertView == null) {
    		LayoutInflater li = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    		convertView = li.inflate(textViewResourceId, null);
    	}
    	Category category = categories.get(position);
    	((TextView)convertView).setText(category.getName1());
    	return convertView;  
    }

}
